//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using DNAide.Web.UI.Styles;

namespace DNAide.Configuration
{
	public class StyleAideConfig : ConfigurationElement
	{

		[ConfigurationProperty("regexCompilationMode", DefaultValue = "Compiled", IsRequired = false)]
		public RegexCompilationType RegexCompilationMode
		{
			get
			{
				return (RegexCompilationType)this["regexCompilationMode"];
			}
			set
			{
				this["regexCompilationMode"] = value;
			}
		}


		[ConfigurationProperty("defaultObfuscateType", DefaultValue = StyleObfuscateType.None, IsRequired = false)]
		public StyleObfuscateType DefaultObfuscateType
		{
			get
			{
				return (StyleObfuscateType)this["defaultObfuscateType"];
			}
			set
			{
				this["defaultObfuscateType"] = value;
			}
		}

		[ConfigurationProperty("defaultRegisterLocationType", DefaultValue = StyleRegisterLocationType.Head, IsRequired = false)]
		public StyleRegisterLocationType DefaultRegisterLocationType
		{
			get
			{
				return (StyleRegisterLocationType)this["defaultRegisterLocationType"];
			}
			set
			{
				this["defaultRegisterLocationType"] = value;
			}
		}

		[ConfigurationProperty("defaultControl", DefaultValue = "", IsRequired = false)]
		public String DefaultControl
		{
			get
			{
				return (String)this["defaultControl"];
			}
			set
			{
				this["defaultControl"] = value;
			}
		}


		[ConfigurationProperty("mimeType", DefaultValue = "text/css", IsRequired = false)]
		public String MimeType
		{
			get
			{
				return (String)this["mimeType"];
			}
			set
			{
				this["mimeType"] = value;
			}
		}


		[ConfigurationProperty("batchIncludes", DefaultValue = false, IsRequired = false)]
		public Boolean BatchIncludes
		{
			get
			{
				return (bool)this["batchIncludes"];
			}
			set
			{
				this["batchIncludes"] = value;
			}
		}


		[ConfigurationProperty("useCompressionHandler", DefaultValue = false, IsRequired = false)]
		public Boolean UseCompressionHandler
		{
			get
			{
				return (bool)this["useCompressionHandler"];
			}
			set
			{
				this["useCompressionHandler"] = value;
			}
		}


		[ConfigurationProperty("defaultMedia", DefaultValue = "screen,projection", IsRequired = false)]
		public String DefaultMedia
		{
			get
			{
				return (string)this["defaultMedia"];
			}
			set
			{
				this["defaultMedia"] = value;
			}
		}


		/// <summary>
		/// Collection of replacement rules
		/// </summary>
		[ConfigurationProperty("globalReplacementRules", IsRequired = false, IsDefaultCollection = true)]
		public StyleAideReplacementRuleConfigCollection GlobalReplacementRules
		{
			get
			{
				return (StyleAideReplacementRuleConfigCollection)this["globalReplacementRules"];
			}
		}

	}


	/// <summary>StyleAideReplacementRuleConfigCollection</summary>
	public class StyleAideReplacementRuleConfigCollection : ConfigurationElementCollection, ICollection<StyleAideReplacementRuleConfig>
	{
		/// <summary>IsReadOnly</summary>
		public new bool IsReadOnly
		{
			get
			{
				return base.IsReadOnly();
			}
		}

		/// <summary>HttpCompressionModuleMimeTypeConfig</summary>
		public StyleAideReplacementRuleConfig this[int index]
		{
			get
			{
				return (StyleAideReplacementRuleConfig)BaseGet(index);
			}
			set
			{
				if (BaseGet(index) != null)
				{
					BaseRemoveAt(index);
				}
				BaseAdd(index, value);
			}
		}

		/// <summary>HttpCompressionModuleMimeTypeConfig</summary>
		new public StyleAideReplacementRuleConfig this[string matchExpression]
		{
			get
			{
				return (StyleAideReplacementRuleConfig)BaseGet(matchExpression);
			}
		}

		/// <summary>HttpCompressionModuleMimeTypeConfig</summary>
		public StyleAideReplacementRuleConfigCollection()
		{
		}

		/// <summary>Add</summary>
		public void Add(StyleAideReplacementRuleConfig item)
		{
			if (item == null)
				return;

			BaseAdd(item);
		}

		/// <summary>Clear</summary>
		public void Clear()
		{
			BaseClear();
		}

		/// <summary>Contains</summary>
		public bool Contains(StyleAideReplacementRuleConfig item)
		{
			if (BaseIndexOf(item) >= 0)
				return true;
			else
				return false;
		}

		/// <summary>CopyTo</summary>
		public void CopyTo(StyleAideReplacementRuleConfig[] array, int arrayIndex)
		{
			((ICollection<StyleAideReplacementRuleConfig>)this).CopyTo(array, arrayIndex);
		}

		/// <summary>CreateNewElement</summary>
		protected override ConfigurationElement CreateNewElement()
		{
			return new StyleAideReplacementRuleConfig();
		}

		/// <summary>IndexOf</summary>
		public int IndexOf(StyleAideReplacementRuleConfig item)
		{
			if (item == null)
				return -1;

			return BaseIndexOf(item);
		}

		/// <summary>GetElementKey</summary>
		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((StyleAideReplacementRuleConfig)element).MatchExpression;
		}

		/// <summary>GetEnumerator</summary>
		public new IEnumerator<StyleAideReplacementRuleConfig> GetEnumerator()
		{
			for (int i = 0; i < Count; i++)
			{
				yield return (StyleAideReplacementRuleConfig)this[i];
			}
		}

		/// <summary>Remove</summary>
		public bool Remove(StyleAideReplacementRuleConfig item)
		{
			if (item == null)
				return false;

			if (BaseIndexOf(item) >= 0)
				BaseRemove(item.MatchExpression);

			return true;
		}

		/// <summary>Remove</summary>
		public void Remove(string matchExpression)
		{
			BaseRemove(matchExpression);
		}

		/// <summary>RemoveAt</summary>
		public void RemoveAt(int index)
		{
			BaseRemoveAt(index);
		}

	}
}
